// riderDistribution/pages/orderDetail/orderDetail.js
var common = require("../../../common/common.js").common;

Page({
    /**
   * 页面的初始数据
   */
    data: {
        order_id: "",
        lat: "",
        lng: ""
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.setData({
            order_id: options.id
        });
        this.getLocate();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    getLocate: function() {
        let that = this;
        common.getAppBase().then(() => {
            common.getCurrentLocation(that.data.appBase.location_key).then(() => {
                that.getDetail();
            });
        });
    },
    getDetail: function() {
        let _this = this;
        let {order_id: order_id, lat: lat, lng: lng} = _this.data;
        let params = {
            order_id: order_id,
            lat: lat,
            lng: lng
        };
        common.request({
            endpoint: "Rider/rider/rider-order-detail",
            method: "post",
            data: params,
            success: res => {
                _this.setData({
                    details: res.extra
                });
            }
        });
    },
    onPageTap: function(e) {
        wx.navigateTo({
            url: e.currentTarget.dataset.url
        });
    },
    makePhone: function(e) {
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.url
        });
    },
    order_copy: function(e) {
        var copy = e.currentTarget.dataset.copy;
        wx.setClipboardData({
            data: copy,
            success: function(res) {
                wx.showToast({
                    title: "复制成功",
                    icon: "succes",
                    duration: 1e3,
                    mask: true
                });
            }
        });
    }
});